#ifndef __NATSUME_SplitTool_h__
#define __NATSUME_SplitTool_h__

#include "cppjieba/Jieba.hpp"
#include <cctype>
#include <cstdlib>
#include <set>
#include <string>
#include <vector>

namespace NATSUME {

    // 前向声明, 避免头文件重复引用
    class Configuration;

    // 分词工具基类 (抽象基类)
    class SplitTool {
        public:
            SplitTool() = default;
            virtual ~SplitTool() = default;

        public:
            // 中文分词函数
            virtual std::vector<std::string>    
            cutCN(const std::string & sentence) = 0;
            // 英文分词函数
            virtual std::vector<std::string>    
            cutEN(const std::string & sentence) = 0;
    };

    // 分词工具的具体实现类 (使用CppJieba库实现)
    class SplitToolCppJieba : public SplitTool {
        public:
            SplitToolCppJieba(Configuration * conf);
            ~SplitToolCppJieba();

        public:
            std::vector<std::string>
            cutCN(const std::string & sentence) override;
            
            std::vector<std::string>
            cutEN(const std::string & sentence) override;

        private:
            Configuration       *m_pConf;
            cppjieba::Jieba     *m_pJieba;
    };


    // 分词工具创建工厂类
    class SplitToolManager {
        public:
            // 创建SplitTool实例
            static SplitTool * 
            create(Configuration * conf);
            // 销毁SplitTool实例
            static void 
            destroy(SplitTool * splitTool);
    };


    // 对中文分词后的句子, 进行停用词去重
    inline void 
    DISTINCT_StopWord(const std::vector<std::string> & words,
                            std::vector<std::string> & result,
                            const std::set<std::string> & stopWordList)
    {
        for (const std::string & word : words) {
            if (std::isspace(word[0]) || std::isdigit(word[0]))
                continue;
            
            auto it = stopWordList.find(word);
            if (it == stopWordList.end()) 
                result.emplace_back(word);
        }
    }

}; 

#endif // __NATSUME_SplitTool_h__